home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / docdemos / restricteddemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-09  |  1.3 KB  |  46 lines

  1. program RestrictedDemo;
  2.  
  3. type
  4.   UnrestrictedRecord = record
  5.     a : Integer;
  6.   end;
  7.   RestrictedRecord = restricted UnrestrictedRecord;
  8.  
  9. var
  10.   r1 : UnrestrictedRecord;
  11.   r2 : RestrictedRecord;
  12.   i : restricted Integer;
  13.   k : Integer;
  14.  
  15.   function AccessRestricted (p : UnrestrictedRecord) : RestrictedRecord;
  16.   var URes : UnrestrictedRecord;
  17.   begin
  18.     { The parameter is treated as unrestricted, even though the actual
  19.       parameter may be a restricted object }
  20.     URes.a := p.a;
  21.     { It is legal to assign a return value }
  22.     AccessRestricted := URes;
  23.   end;
  24.  
  25. begin
  26.   r1.a := 354;
  27.  
  28.   { Assigning a restricted return value to a restricted object }
  29.   { @@ Verify if this should really be allowed????? }
  30.   r2 := AccessRestricted (r1);
  31.  
  32.   { Passing a restricted object to unrestericted formal parameter is ok }
  33.   r2 := AccessRestricted (r2);
  34.  
  35.   {$ifdef BUG}
  36.   { *** The following statements are illegal *** }
  37.   r2.a := 100;    { field access }
  38.   r1 := r2;       { assignment source is restricted }
  39.   r2 := r1;       { assignment target is restricted }
  40.   r1 := AccessRestricted (r2); { assigning a restricted return
  41.                                   value to an unrestricted object }
  42.   i  := 16#ffff;  { assignment target is restricted }
  43.   k  := i + 2;    { arithmetic with restricted value }
  44.   {$endif}
  45. end.
  46.